﻿Public Class UC_Login
    Dim t As New DTOTaiKhoan
    dim n As New DTONhanVien
    Private Sub btnlogin_Click(sender As Object, e As EventArgs) Handles btnlogin.Click
        Kiemtra
    End Sub
    Sub Kiemtra()
        If txtpass.Text = "" Or txtuser.Text = "" Then
            MsgBox("Chưa nhập đủ thông tin!")
            Return
        End If
        t.Username = txtuser.Text
        t.Password = txtpass.Text
        Dim sql As String = String.Format("select * from NHANVIEN n, TaiKhoan t where t.MaNV = n.MaNV and t.Username = '{0}'", t.Username)
        Dim dr As DataRow
        Dim dt As New DataTable
        dt = DataProvider.LoadTable(sql)
        If dt.Rows.Count = 0 Then
            MsgBox("Sai Username hoặc Password")
            Return
        End If
        dr = dt.Rows(0)
        t.Password = dr("password")
        If txtpass.Text = t.Password Then
            Account.MaCV = dr("MaCV")
            Account.MaNV = dr("MaNV")
            Account.TenNV = dr("TenNV")
            Account.Pass = t.Password
            Account.uname = dr("Username")
            MsgBox("Đăng nhập thành công!")
            txtpass.Text = ""
            txtuser.Text = ""
        Else
            MsgBox("Sai Username hoặc Password")
            Return
        End If
    End Sub
    Private Sub UC_Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class
